package com.yds.views;

import android.animation.Animator;
import android.animation.ValueAnimator;
import android.util.Log;
import android.view.View;
import android.view.ViewPropertyAnimator;
import android.view.animation.LinearInterpolator;

public class YDSViewPropertyAnimator {
    private ViewPropertyAnimator animator;

    private void startViewPropertyAnimator(View view, boolean b) {
        if (null != animator) {
            animator.cancel();
        }
        animator = view.animate();
        animator
                //沿x轴水平移动
                .translationX(b ? 300f : 0f)
                //沿y轴垂直移动
//                .translationY(b ? 300f : 0f)
                //沿x轴滚动
//                .rotation(b ? 90f : 0f)
                //以x轴为基准线翻转
//                .rotationX(b ? 180f : 0f)
                //以y轴为基准线翻转
//                .rotationY(b ? 180f : 0f)
                //透明度
//                .alpha(b ? 0.5f : 1f)
                //水平缩放
//                .scaleX(b ? 0.5f : 1f)
                //垂直缩放
//                .scaleY(b ? 0.5f : 1f)
                //延时启动
                .setStartDelay(10)
                //动画持续时长
                .setDuration(1000)
                //动画插值器
                .setInterpolator(new LinearInterpolator())
                //动画运行状态监听
                .setListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {
                        Log.i("Simon", "onAnimationStart");
                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        Log.i("Simon", "onAnimationEnd");
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {
                        Log.i("Simon", "onAnimationCancel");
                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {
                        Log.i("Simon", "onAnimationRepeat");

                    }
                })
                //理论来讲每10ms运行一次
                .setUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public void onAnimationUpdate(ValueAnimator animation) {
                        Log.i("Simon", "onAnimationUpdate");
                    }
                })
                //启动时必要得操作
                .withStartAction(new Runnable() {
                    @Override
                    public void run() {
                        Log.i("Simon", "withStartAction");
                    }
                })
                //结束时必要得操作
                .withEndAction(new Runnable() {
                    @Override
                    public void run() {
                        Log.i("Simon", "withEndAction");
                    }
                });

    }

}
